from Tkinter import *
import Image

import imageCanvas
reload(imageCanvas)

from autoShownScrollbar import AutoShownScrollbar


def scrolled(_widget, _master, _mode='y', **options):
    frame = Frame(_master)
    widget = _widget(frame, **options)
    xscrollbar = None
    yscrollbar = None
    if 'x' in _mode:
        xscrollbar = AutoShownScrollbar(frame, orient=HORIZONTAL)
        xscrollbar.grid(row=1, column=0, sticky=E+W)
        widget.config(xscrollcommand=xscrollbar.set)
        xscrollbar.config(command=widget.xview)
    if 'y' in _mode:
        yscrollbar = AutoShownScrollbar(frame)
        yscrollbar.grid(row=0, column=1, sticky=N+S)
        widget.config(yscrollcommand=yscrollbar.set)
        yscrollbar.config(command=widget.yview)
        
    widget.grid()
    frame.grid() 
    return widget

def scrolledListbox(master, _mode='y', **options):
    return scrolled(Listbox, master, _mode, **options)
def scrolledText(master, _mode='y', **options):
    return scrolled(Text, master, _mode, **options)
def scrolledCanvas(master, _mode='xy', **options):
    return scrolled(Canvas, master, _mode, **options)

